package spring.mybatis.mapperScan1;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import spring.mybatis.domain.User;
import spring.mybatis.mapper.UserMapper;
import spring.mybatis.service.UserService;
import spring.mybatis.service.UserServiceImpl;

/**
 * mybatis-spring 通过 MapperScannerConfigurer 批量生成 Mapper接口
 *
 * @author ME
 * @date 2021/5/20
 */
public class TestMybatisMapperScan1 {

    public static void main(String[] args) {
        ApplicationContext context = new ClassPathXmlApplicationContext("spring/mybatis/mapperScan1/spring-scanner1.xml");

        UserService service = context.getBean(UserService.class);
        System.out.println("UserService: " + service.getUser(2));
        System.out.println();

        UserMapper mapper = context.getBean(UserMapper.class);
        System.out.println("UserMapper: " + mapper.getUser(5));
        System.out.println();

        System.out.println("old size: " + service.getUsers().size());
        System.out.println();

        User user = new User(999,"Ljy", 23);
        System.out.println("add user: " + service.addUser(user));
        System.out.println("new size: " + service.getUsers().size());
    }

}
